package top.shen33.yang.services.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import top.shen33.yang.model.entity.SysParam;
import top.shen33.yang.mapper.SysParamMapper;
import top.shen33.yang.services.SysParamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 系统参数 服务实现类
 * </p>
 *
 * @author oreilly
 * @since 2018-09-13
 */
@Service
public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, SysParam>implements SysParamService {

   @Override
   public Class clazz() {
        return SysParam.class;
   }


    @Override
    @Transactional
    public void doAdd(SysParam itemSysParam) {

        itemSysParam.insertOrUpdate();
    }

    @Override
    @Transactional
    public void doUpdate(SysParam itemSysParam) {

        itemSysParam.insertOrUpdate();
    }

    @Override
    @Transactional
    public void doDelete(String[] ids) {

        QueryWrapper<SysParam> ew = new QueryWrapper<>();
        ew.in("sid", ids);
        new SysParam().delete(ew);
    }

    @Override
    public SysParam getOne(String sid) {

        //关联查询

        SysParam itemSysParam = getById(sid);

        return itemSysParam;
    }

    @Override
    public List<SysParam> all(SysParam itemSysParam) {

        return this.baseMapper.all(itemSysParam);
    }


        @Override
    public Page<SysParam> pageInfo(Page page, SysParam itemSysParam) {

        List<SysParam> dataList = this.baseMapper.pageInfo(page, itemSysParam);
        if(page ==null ){
            page = new Page(0,10000);
        }
        page.setRecords(dataList);
        return page;
    }


    @Override
    @Transactional
    public void doImport(List<SysParam> dataList) {

        //数据验证

        //保存
        this.saveOrUpdateBatch(dataList);
    }

    @Override
    public SysParam getOneByKey(String skey) {

        QueryWrapper<SysParam> wrapper = new QueryWrapper<>();
        wrapper.eq("skey",skey);
        return new SysParam().selectOne(wrapper);
    }
}
